chore: get rid of compiled dependencies#113
Conversation
e94f720 to
d97b7a9
Compare
README.md
Outdated
| [](https://travis-ci.org/gemini-testing/looks-same) | ||
|
|
||
| Node.js library for comparing images, taking into account human color | ||
| Pure node.js library for comparing images, taking into account human color |
| 3. Install dependencies: | ||
| ```bash | ||
| npm ci | ||
| npm install |
There was a problem hiding this comment.
Removed package-lock because otherwise we would need to update it every time when looks-same package.json is updated
| let rgbColor1 = {}; | ||
| let rgbColor2 = {}; | ||
| let labColor1 = {}; | ||
| let labColor2 = {}; |
There was a problem hiding this comment.
Implemented rgb -> lab conversion cache
It only stores last previous conversion
Considering we usually web screenshots, next pixel in line is usually the same as previous one, so it gives significant performance boost
| if (areColorsSame({color1: data.color1, color2: rgbColor1})) { | ||
| lab1 = labColor1; | ||
| } else if (areColorsSame({color1: data.color1, color2: rgbColor2})) { | ||
| lab1 = labColor2; | ||
| } |
There was a problem hiding this comment.
Checking for "expected" cache colours for "actual" image and vice versa helps with moved objects (like borders)
index.js
Outdated
|
|
||
| const highlightColor = options.highlightColor; | ||
| const resultBuffer = Buffer.alloc(width * height * 3); | ||
| const resultBuffer = Buffer.allocUnsafe(width * height * RGB_IMAGE_CHANNELS); |
There was a problem hiding this comment.
"allocUnsafe", compared to "alloc", does not fill buffer with zeroes
Which is totally fine for us, because we fill the buffer ourselves
| /** | ||
| * @type import('js-graph-algorithms') | ||
| */ | ||
| const jsgraphs = require('../vendor/jsgraphs.min.js'); |
lib/image/image.js
Outdated
| async createBuffer(extension) { | ||
| return this._img.toFormat(extension).toBuffer(); | ||
| if (extension === 'raw') { |
b7218bd to
17354cb
Compare
301a0ee to
0890092
Compare
| this._width = width; | ||
| this._height = height; | ||
| this._channels = channels; | ||
| async init() { |
There was a problem hiding this comment.
"jsquash/png" decode result is a promise. Until it resolves, we can't get access to rbg bytes
"getPixel" is sync
| ## Supported image formats | ||
|
|
||
| JPEG, PNG, WebP, GIF, AVIF, TIFF and SVG images are supported. | ||
|
|
||
| *Note: If you want to compare jpeg files, you may encounter random differences due to the jpeg structure if they are not lossless jpeg files.* | ||
|
|
|
|
||
| const convertRgbaToScanlines = (rgba, width, height) => { | ||
| const stride = width * PNG.RGBA_CHANNELS; | ||
| const scanlines = Buffer.allocUnsafe(height * (1 + stride)); // extra byte for filter |
There was a problem hiding this comment.
"allocUnsafe" is faster, because it does not fill the buffer with zeroes, leaving trash data
thats fine, because we fill it all the way
And thats safe, because we throw, if for some reason buffer wasn't rewritten fully (which would not happen)
| return scanlines; | ||
| } | ||
|
|
||
| exports.convertRgbaToPng = (rgba, width, height, compressionLevel = COMPRESSION_LEVEL) => { |
There was a problem hiding this comment.
Just formatting data to https://www.w3.org/TR/PNG-Chunks.html standards
8 bit rgba deflate png without filter or interlace
3742126 to
68bc878
Compare
| "parse-color": "^1.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@eslint/js": "^8.57.1", |
There was a problem hiding this comment.
старый eslint ругался на динамический импорт
68bc878 to
cc2e246
Compare
cc2e246 to
982b367
Compare
| if (pointer !== resultBuffer.byteLength) { | ||
| throw new Error("Got malformed input while trying to convert rgba to png"); | ||
| } | ||
| return resultBuffer; |
There was a problem hiding this comment.
I didn't look at this piece of code carefully. I hope you did everything correctly according to the specification.
| diffBuffer[diffBufferPos++] = diffColor.R; | ||
| diffBuffer[diffBufferPos++] = diffColor.G; | ||
| diffBuffer[diffBufferPos++] = diffColor.B; | ||
| diffBuffer[diffBufferPos++] = 0xff; |
There was a problem hiding this comment.
why we need to add alpha channel?
There was a problem hiding this comment.
"eight-bit-rgba-to-png" only converts rgba to png, not rgb to png
I checked difference between rgba and rgb weight, and there is no result image size difference because of how deflate works: for a large image its like "9.5M RGBA" vs "9.4M RGB"


No description provided.